﻿using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Web;

namespace hzWeb.Layouts.hzWeb
{
    /// <summary>
    /// Call example: http://sharepoint2010/SDQ1E31Q/_layouts/hzWeb/GetConferenceMeeetingStatus.ashx?meetingId=IM05AG9T
    /// http://api.jquery.com/jquery.ajax/
    /// </summary>
    public partial class GetConferenceMeeetingStatus : IHttpHandler
    {
        public bool IsReusable
        {
            get { return true; }
        }

        public void ProcessRequest(HttpContext context)
        {
            string meetingId = context.Request.QueryString["meetingId"];
            SPContext currentContext = SPContext.Current;
            context.Response.ContentType = "application/json";
            System.Web.Script.Serialization.JavaScriptSerializer jsonSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
            Config config = Config.Instance;
            MeetingRoomServiceClient client = Helper.GetMeetingRoomServiceClient(config.meetingRoomServiceUrl);

            bool isActived = client.IsMeetingActived(config.sipForCreatingMeetingRoom, config.lyncServer, config.userNameForCreatingMeetingRoom, config.passwordForCreatingMeetingRoom, config.domainName, meetingId);
            MeetingStatusResult result = new MeetingStatusResult();
            result.isActived = isActived;
            result.meetingRoomURLPrefix = config.meetingRoomURLPrefix;
            string jsonResult = jsonSerializer.Serialize(result);

            context.Response.Write(jsonResult);
        }
    }

    class MeetingStatusResult {
        public bool isActived { get; set; }
        public string meetingRoomURLPrefix { get; set; }
    }
}
